<template>
	<view class="content">
		<view class="bannerBG">
			
		</view>
		<view class="itemTitle">
			<image style="width: 40upx;height: 40upx;" src="../../static/product/itemheader.png" mode="scaleToFill"></image>
			<text style="font-size: $uni-font-size-sm;color: #433302;margin-left: 20upx;">{{item.name}}</text>
		</view>
		<view class="listItem">
			<view v-if="current!=3"  style="display: flex;justify-content: space-between;align-items: center;">
				<text style="font-size: 30upx;color: #656565;">矿工算力</text>
				<text style="font-size: 30upx;color: #656565;">{{item.computePower}}</text>
			</view>
			<view v-if="current==3"  style="display: flex;justify-content: space-between;align-items: center;margin-top: 20upx;">
				<text style="font-size: 30upx;color: #656565;">年化率</text>
				<text style="font-size: 30upx;color: #FB9C28;">{{item.nhl}}%</text>
			</view>
			<view v-if="current!=3"  style="display: flex;justify-content: space-between;align-items: center;margin-top: 20upx;">
				<text style="font-size: 30upx;color: #656565;">需要支付</text>
				<text style="font-size: 30upx;color: #656565;">{{item.usdt}}USDT/{{item.fil}}FIL</text>
			</view>
			<view style="display: flex;justify-content: space-between;align-items: center;margin-top: 20upx;">
				<text style="font-size: 30upx;color: #656565;">合约周期</text>
				<text style="font-size: 30upx;color: #656565;">{{item.hyzq}}天</text>
			</view>
			<view v-if="current!=3"  style="display: flex;justify-content: space-between;align-items: center;margin-top: 20upx;">
				<text style="font-size: 30upx;color: #656565;">剩余矿机</text>
				<text style="font-size: 30upx;color: #656565;">{{item.kjNum}}份</text>
			</view>
			<view v-if="current!=3"  style="display: flex;justify-content: space-between;align-items: center;margin-top: 20upx;">
				<text style="font-size: 30upx;color: #656565;">服务费率</text>
				<text style="font-size: 30upx;color: #656565;">{{item.fee}}%</text>
			</view>
			<view v-if="current!=3"  style="width: 100%;height: 4upx;background-color: #dddddd;margin-top: 30upx;"></view>
			<view v-if="current!=3"  style="display: flex;justify-content: space-between;align-items: center;margin-top: 20upx;">
				<text style="font-size: 30upx;color: #656565;">封存周期</text>
				<text style="font-size: 30upx;color: #656565;">{{item.fczq}}天</text>
			</view>
		</view>
		<button v-if="item.valid==1" @tap="payConfirm" class="bottom" type="default" style="background-color: #F5CB5B;color: #433302;font-size: $uni-font-size-base;">立即下单</button>
	</view>
</template>

<script>
	export default {
		components: {
			
		},
		data() {
			return {
				token:'',
				item_id:0,
				current:0,
				item:{}
			}
		},
		onLoad(option) {
			var that=this;
			that.item_id = option.id;
			that.current=option.current;
			
			
		},
		onShow(){
			var that=this;
			that.checkToken();
		},

		methods: {
			
			payConfirm:function(){
				var that = this;
				uni.navigateTo({
					url:"../pay/payConfirm?current="+that.current+"&id="+that.item_id
				})
			},
			checkToken(){
				var that=this;
				 uni.getStorage({
				    key: 'token',
				    success: function (res) {
						that.token=res.data;
						that.getDetail(res.data);
				    },
					fail:function(error){
						uni.navigateTo({
							url: `/pages/login/login`
						})
					}});
			},
			//获取详情 1,2 是 矿机 3是存币生息
			getDetail(token){
				
				var that=this;
				var url='';
				if(that.current!=3){
					url = that.serverUrl2 + '/biz/api/v1/cp/kj/'+that.item_id
				}
				else{
					url = that.serverUrl2 +'/biz/api/v1/cp/cbsx/'+that.item_id
				}
				
				uni.request({
						url: url,
						method: "GET",
						header: {
							'content-type': 'application/json',
							'Authorization': 'Bearer '+token
						},
						success: (res) => {
							if (res.data.code == 200) {
								console.log(res.data);
								that.item=res.data.data;
								console.log(that.item);
							}
						},
						complete: (error) => {
							console.log(error);
						}
					})
			},
			
			
		}
	}
</script>

<style lang="scss" scoped>
	.content {
		display: flex;
		flex-direction: column;
		// align-items: center;
		// justify-content: center;
		background-color: #F2F2F2;
	}
	.bannerBG {
		width: 100%;
		height: 340upx;
		background-color: #F6E3B9;
		border-radius:0upx 0upx 30upx 30upx;
	}
	.itemTitle {
		display: flex;
		flex-direction: row;
		flex-wrap: nowrap;
		align-items: center;
		margin-top: -300upx;
		width: 82%;
		margin-left: 4%;
		margin-right: 4%;
	}
	.listItem {
		display: flex;
		flex-direction: column;
		margin-top: 40upx;
		width: 82%;
		margin-left: 4%;
		margin-right: 4%;
		border-radius: 10upx;
		background-color: #FFFFFF;
		padding: 5%;
		margin-bottom: 40upx;
		
	}
	.bottom {
		position: fixed;
		bottom: 0px;
		height: 100upx;
		margin-top: 30upx;
		margin-bottom: 40upx;
		width: 92%;
		margin-left: 4%;
		margin-right: 4%;
	}
</style>
